# 方法一 单个单元格访问
# from openpyxl import Workbook
#
# wb = Workbook()
# ws = wb.active
# ws['A1'] = 42
#
# wb.save('sample1.xlsx')


#方法二 cell方法
# from openpyxl import load_workbook
#
# 加载Excel
# wb = load_workbook('sample1.xlsx')
# 获取工作表
# ws = wb.active
# 在第二行 第一列写入数据
# ws.cell(row=2, column=1, value='I am very happy')
# 保存
# wb.save('sample1.xlsx')


# 方法三 循环写入
from openpyxl import load_workbook

# 加载Excel
wb = load_workbook('sample1.xlsx')
# 获取工作表
ws = wb.active

# 外层循环行
for r in range(1, 100):
    # 内层循环列
    for c in range(1, 40):
        ws.cell(row=r, column=c, value='I am very happy'+str(c))

wb.save('sample1.xlsx')
